<?php
    include_once "../lib/DAL/dmloaidonviDAL.php";
    $host='localhost';
$name='root';
$pass='';
$database='tmas';

if($conn=mysql_connect($host,$name,$pass)) 
 {echo" , " ;}
 else {echo "khong ket noi dc";}
mysql_select_db($database,$conn) or die("khong lay dc CSDL");  
date_default_timezone_set('Asia/Ho_Chi_Minh');
mysql_query("SET NAMES 'UTF8'");
    class dmloaidonviBLL{
     
    function __construct(){
        
    }
    
    function __destruct(){
        
    }
    
    public function getListloaidonvi(){
        $sql = "select * from dm_loaidonvi";
        
        $result = mysql_query($sql) or die(mysql_error());
        $arr = array();
        
        while($row = mysql_fetch_array($result)){
            $arr[] = $this->dmloaidonvi($row);
                        
        }
        return $arr;
    }
   
 public  function dmloaidonvi($row){
        $dmloaidv = new dmloaidonviDAL();
        $dmloaidv->setdmloaidonvi($row['Ma_loaidonvi'],$row['Ten_loaidonvi']);
        return $dmloaidv;
        }
    
    public function insertloaidv($loaidv){
         $sql ="INSERT INTO tmas.dm_loaidonvi 
         ( Ma_loaidonvi,Ten_loaidonvi) 
         VALUES (
            '".$loaidv->getma_loaidonvi()."',
            '".$loaidv->getten_loaidonvi()."'
        )";
          $result = mysql_query($sql) or die (mysql_error());
       return $result;
    }
    
    public function updateloaidv($loaidv){
         $sql="UPDATE dm_loaidonvi
            SET
           Ma_loaidonvi = '".$loaidv->getma_loaidonvi()."',
            Ten_loaidonvi = '".$loaidv->getten_loaidonvi()."'
            WHERE Ma_loaidonvi = '".$loaidv->getma_loaidonvi()."'";
         $result = mysql_query($sql) or die (mysql_error());
       return $result;
        
    }
  
    public function deleteloaidv($maloaidv){
         $sql="delete from dm_loaidonvi where Ma_loaidonvi = '".$maloaidv."'";
         $result = mysql_query($sql) or die (mysql_error());
       return $result;
        
    }
    public function getListdmloaidonvibyID($id){
            $sql= " SELECT * FROM dm_loaidonvi WHERE Ma_loaidonvi = '".$id."'";
            $result = mysql_query($sql) or die(mysql_error());
            $arrcvl=array();
            while($row = mysql_fetch_array($result)){
                $arrcvl[]=$this->dmloaidonvi($row);
            }
            return $arrcvl[0];
        }

   
    
   
}
    ?>